package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateLengthDisplayRightMessage extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8610625244704963001L;

	private String submitvalidate;

	private String rightimage;

	private String rightwordcolor;

	public String getRightwordcolor() {
		return rightwordcolor;
	}

	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}

	public String getRightimage() {
		return rightimage;
	}

	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}

	public String getSubmitvalidate() {
		return submitvalidate;
	}

	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}

	@Override
	public int doStartTag() throws JspException {

		JspWriter out = this.pageContext.getOut();

		try {
			out.print(validatelengthdisplayrightmessage());
		} catch (IOException e) {
			// TODO 自动生成 catch 块

			e.printStackTrace();
		}
		return super.doStartTag();
	}

	public StringBuffer validatelengthdisplayrightmessage() {
		StringBuffer str = new StringBuffer();
		String emptyelement = "";
		String pluselement = "";
		if (this.submitvalidate.equalsIgnoreCase("true")) {
			emptyelement = "emptyelement(realname);";
			pluselement = "else pluselement(realname);";
		}
		str.append(returnfunction());
		str.append("<script language=\"javascript\">");
		str
				.append("function  validatelengthdisplayrightmessage(realvalue,min,max,spanname,realname) {");

		str.append("if(realvalue!=\"\") ");
		// this.displayempty();
		// if(this.submitvalidate.equalsIgnoreCase("true")){
		// str.append("dilivery(nextelementname);");
		// }
		// str.append("}");
		// str.append("else {");
		str.append("if(ValidateLength(realvalue,min,max,realname,spanname)) {");
		str.append("	displayrightmessage(realvalue,spanname,realname);");
		str.append(emptyelement);
		// if(this.submitvalidate.equalsIgnoreCase("true")){
		// str.append("dilivery(nextelementname);");
		// }
		str.append("}");
		str.append(pluselement);
		str.append("else {");
		str.append(this.displayempty());
		str.append(emptyelement);
		str.append("}");

		str.append("}");
		// str.append("}");
		str.append("</script>");
		return str;
	}

	public StringBuffer returnfunction() {
		StringBuffer str = new StringBuffer();
		ValidateLength validatelength = new ValidateLength();
		validatelength.setWordcolor(wordcolor);
		validatelength.setWrongimage(wrongimage);
		str.append(validatelength.validatelength());
		DisplayRightMessage displayrightmessage = new DisplayRightMessage();
		displayrightmessage.setWordcolor(wordcolor);
		displayrightmessage.setWrongimage(wrongimage);
		displayrightmessage.setRightimage(rightimage);
		displayrightmessage.setRightwordcolor(rightwordcolor);
		str.append(displayrightmessage.displaymessage());

		return str;
	}
}
